﻿Imports System.Object
Imports VSModel
Imports Cls_Common
Imports System.IO
Imports System.Data
Partial Class FrontEnd_Control_News_Detail
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Not Page.RouteData.Values("Id") Is Nothing Then
                Dim newID As Integer = Page.RouteData.Values("Id")
                LoadData(newID)
            End If
        End If
    End Sub
    Private Sub LoadData(ByVal intID As Integer)
        Using Data As New VSEntities
            Dim p = (From q In Data.Contents Where q.Id = intID And q.StatusId = 3 And q.PublishedDate <= Now() And (q.eEffectiveDate >= Now() Or q.eEffectiveDate Is Nothing) Order By q.PublishedDate Descending Select New With {q.Title, q.QueryString, q.Id, q.Image, q.MenuId, .MenuName = q.Menu.Title, q.Description, q.Contents, q.Author, q.PublishedDate}).FirstOrDefault
            If Not p Is Nothing Then
                hplTitle.Text = p.Title
                'ltrTitle.Text = p.Title
                ltrDes.Text = p.Description
                ltrContent.Text = p.Contents
                ltrAuthor.Text = p.Author
                'lblDate.Text = DateToString(p.PublishedDate, "mm/dd/yyyy")
                'New relation
                'Lay toan bo cap con cua Menu
                Dim a = (From r In Data.uspSelectSubMenu(p.MenuId) Select r.MenuId).ToArray
                Dim h = (From q In Data.Contents Where q.Id <> intID And (q.MenuId = p.MenuId Or a.Contains(q.MenuId)) And q.StatusId = 3 And q.PublishedDate <= Now() And (q.eEffectiveDate >= Now() Or q.eEffectiveDate Is Nothing) Order By q.PublishedDate Descending Select New With {q.Title, q.QueryString, q.Id, q.PublishedDate, q.TypeId, q.MenuId}).Skip(0).Take(10).ToList
                rptRelation.DataSource = h
                rptRelation.DataBind()
            End If
        End Using
    End Sub

    Protected Sub rptRelation_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptRelation.ItemDataBound
        Dim row = CType(e.Item.DataItem, Object)
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)
        Dim lblDate As Label = CType(e.Item.FindControl("lblDate"), Label)
        hplTitle.Text = row.Title
        hplTitle.NavigateUrl = MainDomain & row.MenuId & "/" & row.QueryString & "-" & row.Id.ToString & arrTypeLink(row.TypeId) & ".html"
        lblDate.Text = DateToString(row.PublishedDate, "mm/dd/yyyy")
    End Sub
End Class
